package com.roger.query.service.impl;

import org.apache.lucene.index.Term;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;

import com.roger.query.service.QueryService;
import com.roger.vo.PhrasesQueryParams;

/**
 * 短语查询(短语的前后顺序可变，这个是和SpanNearQuery最重要的区别)
 * @author luoweiyi
 *
 */
public class PhraseQueryServiceImpl implements QueryService<PhrasesQueryParams>{

	@Override
	public Query getQuery(PhrasesQueryParams params) {
		PhraseQuery query = new PhraseQuery();
		query.setSlop(params.getSlop());
		for(String word : params.getPhrases()){
			query.add(new Term(params.getField(),word));
		}
		return query;
	}

}
